
function editOne(e, commodity_id, commodity_name, commodity_stock, commodity_price, commodity_catatory, commodity_desc){
    span = e.target || e.srcElement;

    document.getElementById('id_edit_commodity_id').value = commodity_id;
    document.getElementById('commodity_id').value = commodity_id;
    document.getElementById('id_edit_commodity_name').value = commodity_name;
    document.getElementById('id_edit_commodity_stock').value = commodity_stock;
    document.getElementById('id_edit_commodity_price').value = commodity_price;
    document.getElementById('id_edit_commodity_catagory').value = commodity_catatory;
    document.getElementById('id_edit_commodity_desc').value = commodity_desc;

    $("#editDialog").dialog({
            show : "blind",
            hide : "explode",
            minWidth : 300,
            minHeight : 250,
            modeal : true
        });
}

function checkEditValue(e){
    var name = document.getElementById('id_edit_commodity_name').value;
    var text = "";
    if(name == null || name == ""){
        text += "商品名称不能为空\n";
    }

    var stock = document.getElementById('id_edit_commodity_stock').value;
    if(stock == null || stock == ""){
        text += "库存不能为空!\n";
    }else if(checkInt(stock)){
        text += "库存必须为整数\n";
    }

    var price = document.getElementById('id_edit_commodity_price').value;
    if(price == null || price == ""){
        text += "单价不能为空\n";
    }

    if(text != ""){
        alert(text);
        e.returnValue = false;
        if(e.preventDefault) e.preventDefault();
    }
    return true;
}

function checkInt(input){
    var re = "^-?\\d+$";
    return re.test(input);
}

function deleteOne(e){
    r = confirm("确认删除么？")
    span = e.target || e.srcElement;
    var _del_item = $(span).parent().parent();
    if(r){
        $.ajax({
            type: "POST",
            url: "/warehouse/commodity/delete/",
            data:{
                "commodity_id" : $(span).attr('item')
                  },
            success: function(data, response, statusText){
                if(data.result){
                    $(_del_item).remove();
                    alert(data.message);
                }else{
                    alert(data.message);
                    return false;
                }
            },
            error:function(jqXHR, jqMSG, jqErr){
                alert("删除失败!");
            }
        })
    }else{
        return false;
    }
}
